package com.erps.CommonUtils;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

public class GZipDemo {
	public static void main(String[] args) throws IOException {
		// gzipFile("D:\\administrator\\android.txt","D:\\android.gz");
		// ungzipFile("D:\\android.gz","D:\\android.txt");
		GZipDemo z1 = new GZipDemo();
		GZipDemo z2 = new GZipDemo();
		System.out.println(z1 == z2);
		System.out.println(z1.getClass() == z2.getClass());
	}

	static void gzipFile(String source, String target) throws IOException {
		FileInputStream in = new FileInputStream(source);
		FileOutputStream out = new FileOutputStream(target);
		GZIPOutputStream gout = new GZIPOutputStream(out);

		byte b[] = new byte[1024];
		int num;
		while ((num = in.read(b)) != -1) {
			gout.write(b, 0, num);
		}
		gout.close();
		out.close();
		in.close();
	}

	static void ungzipFile(String source, String target) throws IOException {
		FileInputStream in = new FileInputStream(source);
		FileOutputStream out = new FileOutputStream(target);
		GZIPInputStream gin = new GZIPInputStream(in);
		byte b[] = new byte[1024];
		int num;
		while ((num = gin.read(b)) != -1) {
			out.write(b, 0, num);
		}
		out.close();
		gin.close();
		in.close();
	}
}